<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>通过mapState函数访问State中数据</title>
  <link rel="stylesheet" href="../css/base.css">
  <script src="../js/vue.js"></script>
  <script src="../js/vue_router.js"></script>
  <script src="../js/vuex.js"></script>
  <style>

  </style>
</head>
<!-- 
  组件访问State中数据的第二种方式
    1.从vuex中需要导入mapState函数
      import {mapState} from "vuex";
      通过刚才导入的mapState函数，将当前组件需要的全局函数，映射为当前组件的computed计算属性中
    2.将全局数据，映射为当前组件的计算属性
       computed:{
         ...mapState(["count"])
       }
       若通过script引入的vuex,则需要改为
        computed:{
         ...Vuex.mapState(["count"])
       }
 -->

<body>
  <div id="app">
    <h1 style="color: pink; text-align: center;">{{haha}}</h1>
    <input type="button" value="点我增加数据了" @click="handle">
  </div>
</body>
<script>
  "use strict";
  const store = new Vuex.Store({
    state: {
      haha: 0
    }
  });


  const vm = new Vue({
    el: "#app",
    data() {
      return {

      }
    },
    methods: {
      handle() {}
    },
    store,
    computed: {
      ...Vuex.mapState(["haha"])
    }
  });
</script>

</html>